﻿using System;
using System.IO;
using YArchitech.LIB;

namespace SystemDiagramNew.SystemDiagramLegend.DataDefine
{
	public class LegendInfoFilePathKit
	{
		public static string LegendDataFilePath()
		{
			string text = Path.Combine(Product.WorkingLocation, "exportSystemDiagramLegendInfo.xml");
			string text2 = Path.Combine(Product.DataLocation, "exportSystemDiagramLegendInfo.xml");
			bool flag = false;
			if (!File.Exists(text))
			{
				flag = true;
			}
			if (File.GetLastWriteTime(text) < File.GetLastWriteTime(text2))
			{
				flag = true;
			}
			if (flag)
			{
				LegendInfoFilePathKit.CopyFile(text2, text);
			}
			return text;
		}

		public static string LegendMappingInfoFilePath()
		{
			string text = Path.Combine(Product.WorkingLocation, "mappingWithFamily2ndLegend.xml");
			string text2 = Path.Combine(Product.DataLocation, "mappingWithFamily2ndLegend.xml");
			bool flag = true;
			if (!File.Exists(text))
			{
				flag = true;
			}
			if (File.GetLastWriteTime(text) < File.GetLastWriteTime(text2))
			{
				flag = true;
			}
			if (flag)
			{
				LegendInfoFilePathKit.CopyFile(text2, text);
			}
			return text;
		}

		private static void CopyFile(string sourceFileName, string destFileName)
		{
			try
			{
				Directory.CreateDirectory(Path.GetDirectoryName(destFileName));
				File.Copy(sourceFileName, destFileName, true);
			}
			catch (Exception)
			{
			}
		}
	}
}
